package com.webchat.aigc.llm;


import com.webchat.domain.dto.aigc.ChatCompletionMessageRequest;
import com.webchat.domain.vo.llm.ChatCompletionMessage;
import com.webchat.domain.vo.llm.ChatCompletionResponse;
import com.webchat.domain.vo.llm.ChatMessageRole;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class LlmChatService {


    @Value("${llm.config.model:deepseek}")
    private String modal;


    public String chat(ChatCompletionMessageRequest chatCompletionMessageRequest) {

        final List<ChatCompletionMessage> messageList = Arrays.asList(
                new ChatCompletionMessage(ChatMessageRole.USER.value(),
                        chatCompletionMessageRequest.getPrompt()));
        AbstractLLMChatService abstractLLMChatService = LLMServiceFactory.getLLMService(modal);
        try {
            ChatCompletionResponse chatCompletionResponse = abstractLLMChatService.chat(messageList);
            return chatCompletionResponse.getChoices().get(0).getMessage().getContent();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
